home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ETO Development Tools 4
/
ETO Development Tools 4.iso
/
Essentials
/
C++ A'Link Files
/
Mar 91
/
CPlus.Dev$ 3⁄22⁄91
/
0286-Problem with Referen-Mar91
next >
Wrap
Text File
|
1991-04-01
|
1KB
|
74 lines
Item 1982455 19-March-91 10:50PST
From: D0816 Capilano Computing, MacKenzie,PRT
To: CPLUS.DEV$ C++ Interest List--Developers
Item forwarded by B0231 to BENM
------------------------------------------------------------------------------
Sub: Problem with Reference Variabl
I am new to C++ and having some problems with using reference variables.
The problem came up when I was doing exercise 6 in chapter 7 of Bjarne
Stroustrup's Book. The following code is simplified so as to make it easy to
see the problem.
class classA
{
int x;
int z;
};
class classB : public classA
{
int t;
int s;
};
void Next(classA* &p1)
{
p1=0;
}
main()
{
classB *p ;
Next(p); // This is line 27
return 0;
}
Question:
Why do I get the following warning :
File "test.c"; line 27 # warning: conversion of lvalue needed: temporary used
to initialize reference
If you compile this with the -c option you will see that C++ puts "p" into a
temporary variable and then passes the the address of it to Next. It does not
copy the contents of the temporary variable back into p.
Question 2:
Is this a bug or am I doing something wrong.
In the exercise I was doing Next was really a routine for returning the next
entry on a linked list.
Thanks
Neil